home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.09 Sep 91 / MacsbugSourceCode.p -- MPW
Encoding:
Text File  |  1991-06-23  |  1.7 KB  |  67 lines  |  [TEXT/MPS ]

  1. FUNCTION     LongToString(theLong:longint):str255;
  2. {simple glue routine takes integer or longint     and returns string containing value}
  3. var
  4.     theString: str255;
  5. begin
  6.     NumToString(theLong,theString);
  7.     LongToString := theString;
  8. end;
  9.  
  10. FUNCTION LongToHexString (number: UNIV     longint): str255;
  11. {takes longint and returns a string containing     value in hex}
  12. CONST
  13.     digits = '0123456789ABCDEFX';
  14. VAR
  15.     hex: Str255;
  16.     hexIndex: INTEGER;
  17.     negative: BOOLEAN;
  18. BEGIN
  19.     hex[0]:=chr(9);{set length of hex to 9}
  20.     hex[1] := '$';
  21.     IF number < 0 THEN BEGIN
  22.           number:=bitAnd(number,maxLongint);  
  23.         { mask off leading negative bit}
  24.           negative := true;
  25.          END
  26.     ELSE negative := false;
  27.  
  28.     FOR hexIndex := 9 DOWNTO 3 DO BEGIN
  29.     hex[hexIndex]:=digits[1+(numberMOD 16)]; 
  30.     {put digit into hex string}
  31.     number:= number DIV longint(16);
  32.         END;
  33.  
  34.     IF negative THEN 
  35.      hex[2]:=digits[1+(number MOD 16) + 8]
  36.     ELSE hex[2]:=digits[1+(number MOD 16)];
  37.     LongToHexString := hex;
  38. END;
  39.  
  40. FUNCTION PtrToHexString( aPtr: UNIV ptr): str255;
  41. {takes Ptr and returns string containing value     in hex. StripAddress is called on the Ptr.}
  42. CONST
  43.     digits = '0123456789ABCDEF';
  44. VAR
  45.    hex: string[10];
  46.    hexIndex: INTEGER;
  47.    number: longint;
  48. BEGIN
  49.   hex[0] := chr(9); {set length of hex to 9}
  50.   hex[1] := '$';
  51.   number := longint(StripAddress(aPtr));
  52.   FOR hexIndex := 9 DOWNTO 2 DO
  53.     BEGIN
  54.       hex[hexIndex]:=digits[1+(number MOD16)];         {put digit into hex string}
  55.       number := number DIV longint(16);
  56.     END;
  57.     PtrToHexString := hex;
  58. END;
  59.  
  60. FUNCTION BooleanToString(theBoolean:Boolean): str255;
  61. { glue routine takes boolean and returns     string containing value}
  62. begin
  63.     if theBoolean
  64.         then BooleanToString := 'true'
  65.         else BooleanToString := 'false';
  66. end;
  67.